by the skin of (someone's) teeth

Translations
чудом, едва
He passed the exam by the skin of his teeth.
Он сдал экзамен чудом.
Definitions
A phrase used to describe a situation where someone narrowly escapes a difficult or dangerous situation, achieving success or survival by a very small margin.